package com.demomaster.quickaccessibility.plugin;

import android.view.accessibility.AccessibilityEvent;

public abstract class Plugin implements IPlugin {
    public long lastTriggerTime = -1;
    boolean isRunning = false;

    @Override
    public String getPluginId() {
        return null;
    }

    @Override
    public String getPluginName() {
        return null;
    }

    @Override
    public int getPluginVersionCode() {
        return 1;
    }

    @Override
    public boolean isEnable() {
        return true;
    }

    @Override
    public void onDispatchEvent(AccessibilityEvent event, String packageName, String activityName) {
        if (!isEnable()) {
            return;
        }
        if (System.currentTimeMillis() - lastTriggerTime < getEventInterval()) {
            return;
        }

        eventStart();
        onAccessibilityEvent(event, packageName, activityName);
        eventEnd();
    }

    @Override
    public void eventStart() {
        //isRunning = true;
        this.lastTriggerTime = System.currentTimeMillis();
    }

    @Override
    public void eventEnd() {
        //isRunning = false;
        this.lastTriggerTime = System.currentTimeMillis();
    }

    public long getLastTriggerTime() {
        return lastTriggerTime;
    }

    @Override
    public long getEventInterval() {
        return 100;//触发间隔
    }
}
